<script setup lang="ts">
	import Menu from './layout/aside/Menu.vue'
	import Header from './layout/header/index.vue'
	import Footer from './layout/footer/index.vue'
  import {computed,  onMounted, onUnmounted, ref} from "vue";
  import {useSettingStore} from "@/stores/setting.ts";
  const SettingStore = useSettingStore()
  const isCollapse = computed(() =>!SettingStore.isCollapse)
  const asideWidth = ref<number>(210);
  let isResizing = false;
  let startX = 0;
  let startWidth = 0;

  const startResizing = (event: MouseEvent) => {
    isResizing = true;
    startX = event.clientX;
    startWidth = asideWidth.value;

    document.addEventListener("mousemove", resizeAside);
    document.addEventListener("mouseup", stopResizing);
  };

  const resizeAside = (event: MouseEvent) => {
    if (isResizing) {
      const newWidth = startWidth + (event.clientX - startX);
      asideWidth.value = newWidth > 50 ? newWidth : 50; // 设置最小宽度为 50px
    }
  };

  const stopResizing = () => {
    isResizing = false;
    document.removeEventListener("mousemove", resizeAside);
    document.removeEventListener("mouseup", stopResizing);
  };

  onMounted(() => {
    document.addEventListener("mouseup", stopResizing);
  });

  onUnmounted(() => {
    document.removeEventListener("mouseup", stopResizing);
  });
</script>
<style scoped>
	.common-layout{
		display: flex;
		width:100wh;
		height:97vh;
		.el-container{
      background-color: var(--color-background);
			.el-aside{
				background-color: var(--color-background);
				width: auto;
				text-align: center;
        display: flex;
			}
			.el-aside::-webkit-scrollbar{
				display: none;
			}
			.main{
        background-color: var(--color-background);
				.el-header{
          background-color: var(--color-background);
					align-items: center;
					display: flex;
					height: 10.3%;
					padding-left: 1px;
				}
				.el-main{
          background-color: var(--color-background);
					height:84.7%;
				}
				.el-footer{
          background-color: var(--color-background);
					align-items: center;
					justify-content: center;
					display: flex;
					height: 5%;
				}
			}
		}
	}
  .m-drag{
    background-color: lightgray;
    width: 5px;
    height: 100%;
    cursor: pointer;
  }
</style>
<template>
	<div class="common-layout">
	    <el-container class="el-container">
	      <el-aside class="el-aside">
          <div class="aside-box" :style="{ width: isCollapse ? '1px' : asideWidth + 'px' }">
            <Menu/>
          </div>
          <div class="m-drag" @mousedown="startResizing"></div>
        </el-aside>
	      <el-container class="el-container main">
	        <el-header class="el-header">
            <Header></Header>
          </el-header>
	        <el-main class="el-main">
            <router-view>
            </router-view>
			    </el-main>
	        <el-footer class="el-footer">
            <Footer></Footer>
          </el-footer>
	      </el-container>
	    </el-container>
	</div>
</template>


